<?php
namespace Admin\Form;

use Zend\InputFilter;
use Zend\Form\Form;
use Zend\Form\Element;
use Zend\Db\Adapter\AdapterInterface;

class PhotoForm extends Form
{
	protected $dbAdapter;
    public function __construct(AdapterInterface $dbAdapter)
    {
		$this->setDbAdapter($dbAdapter);
        // we want to ignore the name passed
        parent::__construct('photo');

        $this->setAttribute('method', 'post');
        $this->add(array(
            'name' => 'id',
            'attributes' => array(
                'type'  => 'hidden',
            ),
        ));

      

        $this->add(array(
            'name' => 'tengallery',
            'attributes' => array(
				'id' => 'tengallery',
                'type'  => 'text',
				'required' => 'required',
            ),
            'options' => array(
                'label' => 'Tên Album',
            ),
        ));
		$this->add(array(
            'name' => 'mota',
            'attributes' => array(
				'id' => 'mota',
                'type'  => 'textarea',
				
            ),
            'options' => array(
                'label' => 'Mô tả',
            ),
        ));
		
		$this->addElements();
		
       
        $this->add(array(
            'name' => 'submit',
            'attributes' => array(
                'type'  => 'submit',
                'value' => 'Go',
                'id' => 'submitbutton',
            ),
        ));

    }
	
	
	 public function addElements()
    {
        // File Input
        $file = new Element\File('file');
        $file
            ->setLabel('Hình ảnh')
            ->setAttributes(array(
                'id' => 'hinhanh',
				'name' => 'hinhanh',
				'required' => 'required',
				'multiple' =>true,
            ));
        $this->add($file);

        
    }
	

    public function createInputFilter()
    {
        $inputFilter = new InputFilter\InputFilter();

        // File Input
        $file = new InputFilter\FileInput('hinhanh');
        $file->setRequired(true);
        $file->getFilterChain()->attachByName(
            'filerenameupload',
            array(
                'target'          => 'data',
                'overwrite'       => true,
                'use_upload_name' => true,
            )
        );
        $inputFilter->add($file);

        

        return $inputFilter;
    }
	
	public function setDbAdapter(AdapterInterface $dbAdapter)
    {
        $this->dbAdapter = $dbAdapter;

        return $this;
    }

    public function getDbAdapter()
    {
        return $this->dbAdapter;
    }
}
